package com.ruoyi.web.utils.mobile;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

import com.github.wxpay.sdk.WXPayConfig;

public class WxPayConfigRuImpl implements WXPayConfig {
    private byte[] certData;

//    private WxPayConfigRuImpl(){}

    private static WxPayConfigRuImpl wxPayConfigRu = null;

    public static WxPayConfigRuImpl getInstance() throws Exception {
        if(wxPayConfigRu==null){
            return new WxPayConfigRuImpl();
        }
        return wxPayConfigRu;
    }

    public WxPayConfigRuImpl() throws Exception {
//        this.profiles = profiles;
//        InputStream input = ClassUtils.getDefaultClassLoader().getResourceAsStream("static/icon.png");
        String path = "/usr/local/ruoyi/vshengbao.p12";
//        File file = new ClassPathResource(path).getFile();
        File file = new File(path);
        InputStream certStream = new FileInputStream(file);

        this.certData = new byte[(int) file.length()];

        certStream.read(this.certData);

        certStream.close();

    }


    @Override
    public String getAppID() {
        return "wxb09f6ef3b15db134";
    }

    @Override
    public String getMchID() {
        return "1602615404";
    }

    @Override
    public String getKey() {
        return "2020Tzkj2610Vshengbao888YangMing";
    }

    @Override
    public InputStream getCertStream() {
        ByteArrayInputStream certBis = new ByteArrayInputStream(this.certData);
        return certBis;
    }

    @Override
    public int getHttpConnectTimeoutMs() {
        return 10000;
    }

    @Override
    public int getHttpReadTimeoutMs() {
        return 10000;
    }
}
